package com.gduf.bbl.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;
import java.util.UUID;


import com.gduf.bbl.common.utils.ImgUtil;
import com.gduf.bbl.common.utils.PageUtils;
import com.gduf.bbl.common.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.gduf.bbl.entity.HelplistEntity;
import com.gduf.bbl.service.HelplistService;
import org.springframework.web.multipart.MultipartFile;


/**
 * 
 *
 * @author xqw
 * @email 2041411595@qq.com
 * @date 2024-02-29 20:38:49
 */
@RestController
@RequestMapping("bbl/helplist")
@CrossOrigin(allowCredentials = "true")
@Api(tags = "帮助管理")
public class HelplistController {
    @Autowired
    private HelplistService helplistService;



    @ApiOperation("查询帮助详细信息根据id")
    @GetMapping("/detailInfo")
    //TODO 查询帮助详细信息根据id
    public R getHelpDetailInfo(Integer id){
        return null;
    }






    @PostMapping("/commitExpress")
    @ApiOperation("提交外卖送寝订单")
    public R commitExpress(MultipartFile formId,Integer areaId,String mu,String openid,String qi,String title,double totalFee,Integer userId){
        String formIdStr = ImgUtil.uploadImg(formId);
        final HelplistEntity helplist = new HelplistEntity();
        String orderNo = UUID.randomUUID().toString().replace("-","");
        helplist.setOrderNo(orderNo);
        helplist.setCreareTime(new Date());
        helplist.setIsDelete(2);
        helplist.setImg(formIdStr);
        helplist.setAreaId(areaId);
        helplist.setMu(mu);
        helplist.setType(openid);
        helplist.setQi(qi);
        helplist.setTitle(title);
        helplist.setTotalFee(totalFee);
        helplist.setUserId(userId);
        helplist.setComTime(new Date());
        helplist.setCancelTime(new Date());
        helplist.setPayTime(new Date());
        helplist.setJdTime(new Date());


        boolean save = helplistService.save(helplist);
        if(save){
            return R.ok().setData(orderNo);
        }else{
            return R.error();
        }
    }


    @PostMapping("/commitDelivery")
    @ApiOperation("提交快递代取订单")
    public R commitDelivery(MultipartFile formId,Integer areaId,String mu,String openid,
                         String qi,String title,double totalFee,Integer userId,
                         Integer page,String qjm){
        String formIdStr = ImgUtil.uploadImg(formId);
        final HelplistEntity helplist = new HelplistEntity();
        String orderNo = UUID.randomUUID().toString().replace("-","");
        helplist.setOrderNo(orderNo);
        helplist.setCreareTime(new Date());
        helplist.setIsDelete(2);
        helplist.setImg(formIdStr);
        helplist.setAreaId(areaId);
        helplist.setMu(mu);
        helplist.setType(openid);
        helplist.setQi(qi);
        helplist.setTitle(title);
        helplist.setTotalFee(totalFee);
        helplist.setUserId(userId);
        helplist.setSize(page);
        helplist.setQjm(qjm);
        helplist.setComTime(new Date());
        helplist.setCancelTime(new Date());
        helplist.setPayTime(new Date());
        helplist.setJdTime(new Date());

        boolean save = helplistService.save(helplist);
        if(save){
            return R.ok().setData(orderNo);
        }else{
            return R.error();
        }
    }


    @PostMapping("/commitErrands")
    @ApiOperation("提交校园跑腿信息")
    public R commitHelp3(@RequestBody HelplistEntity helplistEntity){


        String orderNo = UUID.randomUUID().toString().replace("-","");
        helplistEntity.setOrderNo(orderNo);
        helplistEntity.setCreareTime(new Date());
        helplistEntity.setIsDelete(2);
        helplistEntity.setComTime(new Date());
        helplistEntity.setCancelTime(new Date());
        helplistEntity.setPayTime(new Date());
        helplistEntity.setJdTime(new Date());



        boolean save = helplistService.save(helplistEntity);
        if(save){
            return R.ok().setData(orderNo);
        }else{
            return R.error();
        }
    }


    @PostMapping("/commitShopping")
    @ApiOperation("提交物品代购信息")
    public R commitShopping(@RequestBody HelplistEntity helplistEntity){


        String orderNo = UUID.randomUUID().toString().replace("-","");
        helplistEntity.setOrderNo(orderNo);
        helplistEntity.setCreareTime(new Date());
        helplistEntity.setIsDelete(2);
        helplistEntity.setComTime(new Date());
        helplistEntity.setCancelTime(new Date());
        helplistEntity.setPayTime(new Date());
        helplistEntity.setJdTime(new Date());



        boolean save = helplistService.save(helplistEntity);
        if(save){
            return R.ok().setData(orderNo);
        }else{
            return R.error();
        }
    }

    @GetMapping("/getHelpListByAreaId")
    @ApiOperation("获取帮助列表根据校区id")
    public R getHelpListByAreaId(Integer areaId){
        return helplistService.getHelpListByAreaId(areaId);
    }


    @ApiOperation(value = "查询帮助列表根据用户id")
    @GetMapping("/getListByUserId")
    public R getListByUserId(Integer userId){
        return helplistService.getListByUserId(userId);
    }

    @ApiOperation(value = "查询帮助列表根据接单人id")
    @GetMapping("/getListByJdId")
    public R getListByJdIdId(Integer userId){
        return helplistService.getListByJdIdId(userId);
    }


    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = helplistService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		HelplistEntity heiplist = helplistService.getById(id);

        return R.ok().put("heiplist", heiplist);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody HelplistEntity helplist){
        helplist.setCreareTime(new Date());
        helplist.setIsDelete(2);
        boolean save = helplistService.save(helplist);
        if(save){
            return R.ok();
        }else{
            return R.error();
        }

    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@RequestBody HelplistEntity heiplist){
		helplistService.updateById(heiplist);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		helplistService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
